/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author JSJSYS
 */
@WebServlet(urlPatterns = {"/conform"})
public class conform extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            processRequest(request, response);
        } catch (Exception ex) {
            Logger.getLogger(conform.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException, Exception {
        response.setContentType("text/html;charset=UTF-8");
        //输入用户名与密码
        String name = request.getParameter("username");
        String password = request.getParameter("password");
        //保留信息
        request.setAttribute("name", name);
        System.out.println("name:" + name + "password:" + password);
//        String dbname = "admin";
//        String dbcode = "admin";
        int result = 0;
        // Sql re=new Sql();
        result = sql.compl(name, password);

        if (result == 1) {
            // request.setAttribute("cot", count);
            String sn = sql.show(name);
            request.setAttribute("name", sn);
            request.getRequestDispatcher("jsp/user.jsp").forward(request, response);
        } else {
            request.setAttribute("msg", "账号或密码错误，请重新输入");//返回login的错误信息
            request.getRequestDispatcher("jsp/login.jsp").forward(request, response);
        }
    }
}
